package com.caishi.lkx.gateway.apidowngrade;

import com.zzw.common.CommonResultCode;
import com.zzw.common.Result;
import com.zzw.common.gateway.downgrade.ApiDowngrade;
import com.zzw.common.gateway.downgrade.DefaultDowngradeHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

@Component
@Primary
@Slf4j
public class CqvipDefaultDowngradeHandler extends DefaultDowngradeHandler {

    @Override
    public Object handler(ApiDowngrade annotation, Result result, ServletRequest request, ServletResponse response, Object[] args, HandlerMethod handlerMethod) {
        var returnType = handlerMethod.getReturnType().getParameterType();
        if (annotation.downgradeFlag() == 404) return Result.fail(CommonResultCode.notFund);
        return super.handler(annotation, result, request,response, args, handlerMethod);
    }
}
